using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
[RequireComponent(typeof(TextMeshProUGUI))]
public class AutoSizeTMP : LayoutGroup
{
    public float maxlineWidth = 1920f;
    public float minLineWidth = 300f;

    private TextMeshProUGUI m_Text;
    public override void CalculateLayoutInputVertical()
    {
        if (m_Text == null)
        {
            m_Text = GetComponent<TextMeshProUGUI>();
        }
        float newWidth = Mathf.Clamp(m_Text.preferredWidth, minLineWidth, maxlineWidth);
        rectTransform.sizeDelta = new Vector2(newWidth, rectTransform.sizeDelta.y);
        rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, m_Text.preferredHeight);
    }

    public override void SetLayoutHorizontal()
    {

    }

    public override void SetLayoutVertical()
    {

    }
}
